home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The Fatted Calf
/
The Fatted Calf.iso
/
Applications
/
Utilities
/
KPerfMon
/
Source
/
Monitor.m
< prev
next >
Wrap
Text File
|
1992-11-17
|
10KB
|
267 lines
/* Modified by Andrew Loewenstern (andrew@cubetech.com) <drue> */
/* 7/15/92 for 3.0 compatibility. Mainly changed headers and */
/* such... */
/*
Copyright 1991 Scott Hess. Permission to use, copy, modify, and
distribute this software and its documentation for any purpose
and without fee is hereby granted, provided that this copyright
notice appear in all copies. The copyright notice need not appear
on binary-only distributions - just in source code.
Scott Hess makes no representations about the suitability of this
software for any purpose. It is provided "as is" without express
or implied warranty.
*/
/* Generated by Interface Builder */
#import "table_compat.h" /* header file with stuff that was */
/* nuked in 3.0 -- drue */
//#import <mach.h>
//#import <defaults.h> /* these 2 changed in 3.0 -- drue */
#import <mach/mach.h>
#import <defaults/defaults.h>
#import <string.h>
#import <sys/dk.h>
// #import <sys/table.h> /* changed in 3.0 -- drue */
#import <bsd/machine/table.h>
#import <objc/Storage.h>
#import <dpsclient/psops.h>
#import <dpsclient/wraps.h>
#import <appkit/nextstd.h>
#import <appkit/Application.h>
#import <appkit/Matrix.h>
#import "Monitor.h"
#import "AppDelegate.h"
#import "wraps.h"
const int elementsToDisplay = 55; // we display the last <x> events
const int elementsToSave = 250; // but keep around some extras...
extern int table(int,int,void *,int,int); // We need to stick this in because the table call is undocumented.
@implementation Monitor
- initFrame:(NXRect *)frameRect
{
/**************************************************************************************************************************
* Instantiate the NXImages needed for compositing onto the icon (titles and such). *
**************************************************************************************************************************/
cpuTiff = [NXImage findImageNamed:"CPU.tiff"];
vmTiff = [NXImage findImageNamed:"VM.tiff"];
memTiff = [NXImage findImageNamed:"MEM.tiff"];
diskTiff = [NXImage findImageNamed:"DISK.tiff"];
networkTiff = [NXImage findImageNamed:"NET.tiff"];
/**************************************************************************************************************************
* Instantiate the Storage Object needed to keep the statistics *
**************************************************************************************************************************/
stats = [Storage alloc];
[stats initCount:0
elementSize:sizeof(struct perfData)
description:PERFDATA_DESC];
[super initFrame:frameRect];
infoType = -1;
return self;
}
- drawSelf:(NXRect *)rects :(int)rectCount
{
unsigned int total;
struct perfData *old;
/* Note: I should have just translated the coordinates instead of adding 8 to everything, but I was too stupid to think of it at the time. Change it later. */
switch ( infoType )
{
case CPU:
drawCPU(current.system / 2 + 8,
( current.user + current.system ) / 2 + 8,
( current.user + current.system + current.nice) / 2 + 8);
break;
case MEMORY:
total = current.free + current.active + current.inactive + current.wired;
drawMem(current.wired * 50 / total + 8,
( current.wired + current.inactive ) * 50 / total + 8,
( current.wired + current.inactive + current.active ) * 50 / total + 8);
break;
case DISK:
drawDisk(MIN(current.disk,50) + 8,
MIN(current.pagein + current.pageout,50) + 8,
MIN(current.pageout,50) + 8);
break;
case NETWORK:
if ( (old = (struct perfData *)[stats elementAt:[stats count]-2]) == NULL )
drawNet(8,8,8,MIN(current.netin,50)+8,MIN(current.netout,50)+8,MIN(current.netcollision,50)+8);
else
drawNet(MIN(old->netin,50)+8,MIN(old->netout,50)+8,MIN(old->netcollision,50)+8,
MIN(current.netin,50)+8,MIN(current.netout,50)+8,MIN(current.netcollision,50)+8);
break;
}
return self;
}
- flip:sender
{
static NXPoint aPoint = {2,0};
struct perfData *data;
struct perfData *old;
int i;
int type;
int count;
int total;
if ( (type = [[sender selectedCell] tag]) == infoType )
return self;
[self lockFocus];
count = [stats count];
switch ( type )
{
case CPU:
infoType = CPU;
[cpuTiff composite:NX_COPY toPoint:&aPoint];
NXWriteDefault([NXApp appName],"InfoType","0");
for ( i = MAX(count - elementsToDisplay,0) ; i < count ; i++ )
{
data = (struct perfData *)[stats elementAt:i];
drawCPU(data->system / 2 + 8,
( data->user + data->system ) / 2 + 8,
( data->user + data->system + data->nice) / 2 + 8);
}
break;
case MEMORY:
infoType = MEMORY;
[memTiff composite:NX_COPY toPoint:&aPoint];
NXWriteDefault([NXApp appName],"InfoType","1");
for ( i = MAX(count - elementsToDisplay,0) ; i < count ; i++ )
{
data = (struct perfData *)[stats elementAt:i];
total = data->free + data->active + data->inactive + data->wired;
drawMem(data->wired * 50 / total + 8,
( data->wired + data->inactive ) * 50 / total + 8,
( data->wired + data->inactive + data->active ) * 50 / total + 8);
}
break;
case DISK:
infoType = DISK;
[diskTiff composite:NX_COPY toPoint:&aPoint];
NXWriteDefault([NXApp appName],"InfoType","2");
for ( i = MAX(count - elementsToDisplay,0) ; i < count ; i++ )
{
data = (struct perfData *)[stats elementAt:i];
drawDisk(MIN(data->disk,50) + 8,
MIN(data->pagein + data->pageout,50) + 8,
MIN(data->pageout,50) + 8);
}
break;
case NETWORK:
infoType = NETWORK;
[networkTiff composite:NX_COPY toPoint:&aPoint];
NXWriteDefault([NXApp appName],"InfoType","3");
for ( i = MAX(count - elementsToDisplay,1) ; i < count ; i++ )
{
old = (struct perfData *)[stats elementAt:i-1];
data = (struct perfData *)[stats elementAt:i];
drawNet(MIN(old->netin,50)+8,MIN(old->netout,50)+8,MIN(old->netcollision,50)+8,
MIN(data->netin,50)+8,MIN(data->netout,50)+8,MIN(data->netcollision,50)+8);
}
break;
}
[self unlockFocus];
[window flushWindow];
return self;
}
- step
{
struct tbl_cpuinfo tc;
long cp_time[CPUSTATES];
long total;
long temp;
vm_statistics_data_t vmstat;
struct tbl_netinfo netstat;
struct tbl_diskinfo diskstat;
struct tbl_ioinfo iostat;
/**************************************************************************************************************************
* Get the data *
**************************************************************************************************************************/
table(TBL_CPUINFO,0,&tc,1,sizeof(tc));
bcopy(tc.ci_cptime,cp_time,sizeof(cp_time));
vm_statistics(task_self(),&vmstat);
table(TBL_NETINFO,0,&netstat,1,sizeof(netstat));
table(TBL_DISKINFO,0,&diskstat,1,sizeof(diskstat));
table(TBL_IOINFO,0,&iostat,1,sizeof(iostat));
/**************************************************************************************************************************
* Process the data into the proper form. *
**************************************************************************************************************************/
total = cp_time[CP_SYS] + cp_time[CP_USER] + cp_time[CP_NICE] + cp_time[CP_IDLE];
temp = total;
if((total - oldTotal) > 0) /* this was done to fix the div0 error. It */
total -= oldTotal; /* works, but barely... - drue */
oldTotal = temp;
current.system = ( cp_time[CP_SYS] - oldTimes[CP_SYS] ) * 100 / total;
current.user = ( cp_time[CP_USER] - oldTimes[CP_USER] ) * 100 / total;
current.nice = ( cp_time[CP_NICE] - oldTimes[CP_NICE] ) * 100 / total;
bcopy(cp_time,oldTimes,sizeof(cp_time));
current.free = vmstat.free_count;
current.active = vmstat.active_count;
current.inactive = vmstat.inactive_count;
current.wired = vmstat.wire_count;
current.netin = ( netstat.ni_ipackets - oldin ) / pollInterval;
current.netout = ( netstat.ni_opackets - oldout ) / pollInterval;
current.netcollision = ( netstat.ni_collisions - oldcollision ) / pollInterval;
oldin = netstat.ni_ipackets;
oldout = netstat.ni_opackets;
oldcollision = netstat.ni_collisions;
current.disk = ( diskstat.di_xfer - olddisk) / pollInterval;
current.pagein = ( vmstat.pageins - oldpagein ) / pollInterval;
current.pageout = ( vmstat.pageouts - oldpageout ) / pollInterval;
olddisk = diskstat.di_xfer;
oldpagein = vmstat.pageins;
oldpageout = vmstat.pageouts;
[self display];
if ( [stats count] > elementsToSave ) {
[stats removeElementAt:0];
}
[stats addElement:¤t];
return self;
}
@end